<template>
	<view class="tjyp1">
		<headertop title="添加药品" str1="oridei" :back1="back1"></headertop>
		<view class="tjyp1back">

		</view>
		<view :style="{'margin-top':statusBarHeight+'px','width':'100%','height':barHeight+'px'}">
		</view>
		<view class="centersousuo">
			<image :src="_static('/images/Frame@2x(34).png')" class="ssicon" mode=""></image>
			<input type="text" v-model="keyword" placeholder="请输入药品名称进行搜索" />
			<image :src="_static('/images/removeicon.png')" v-if="keyword" @click="sc" class="removeicon" mode="">
			</image>
		</view>
		<view class="yaoping" @click="gopage">
			<image :src="_static('/images/Frame@2x(35).png')" class="ypicon" mode=""></image>
			<span>找不到药品</span>
		</view>
		<view class="yybox">
			<view class="leftmenu">
				<view :class="active1==index?'itembox bj':'itembox'" @click="qiehuan(index)"
					v-for="(item,index) in leftmenu" :key="index">
					<view style="width: 90%;">
						{{item['name']}}
					</view>
				</view>
			</view>
			<view class="rightcontent">
				<view class="msgicon" v-if="!listnr.length">
					<image :src="_static('/images/wxnone.png')" mode="widthFix">
					</image>
					<view class="msgtext">
						暂无内容
					</view>
				</view>
				<view class="centertexts">
					<view class="itemyaoliang" v-for="item in listnr" :key="item.id" v-if="listnr.length"
						@click="xz(item)">
						<view style="width: 90%;">
							{{item['name']}}
						</view>
					</view>
				</view>
			</view>

		</view>
	</view>
</template>

<script setup>
	import headertop from '@/components/header.vue'
	import ulm, {
		$api
	} from '@/ulm';
	import {
		_static
	} from '@/ulm/utils/url.js'
	import {
		ref,
		reactive,
		onMounted,
		watch
	} from 'vue'
	import {
		onPageScroll,
		onLoad,
		onShow,
		onReachBottom
	} from "@dcloudio/uni-app";
	const statusBarHeight = ref('')
	const texts = ref('')
	const barHeight = ref('')
	const back1 = ref('')
	const leftmenu = ref([])
	const active1 = ref(0)
	const listnr = ref([])
	const active = ref(2)
	const keyword = ref('')
	watch(() => keyword.value, (newval, oldval) => {
		medicineListinit(leftmenu.value)
	})
	onShow(() => {
		init()
	})
	onMounted(() => {
		statusBarHeight.value = uni.getSystemInfoSync().statusBarHeight
		const {
			top,
			height
		} = wx.getMenuButtonBoundingClientRect();
		barHeight.value = height ? height + (top - statusBarHeight.value) * 2 : 38;
	})
	onPageScroll((e) => {
		if (e.scrollTop > 100) {
			back1.value = '#81D6FF'
		} else {
			back1.value = ''
		}
	})
	async function init() {
		const res = await $api.fenlei({

		})
		if (res.code == 1) {
			leftmenu.value = res.data
			medicineListinit(res.data)
		}
	}

	function sc() {
		keyword.value = ''
		medicineListinit(leftmenu.value)
	}

	function xz(item) {
		uni.navigateBack()
		uni.setStorageSync('itemobj2', item)
	}

	function gopage() {
		uni.navigateTo({
			url: '/sub_index/index/tianjiayp'
		})
	}
	async function medicineListinit(list) {
		const res = await $api.medicineList1({
			category_id: list[active1.value]['category_id'],
			keyword: keyword.value
		})
		if (res.code == 1) {
			listnr.value = res.data
		}
	}


	function qiehuan(e) {
		active1.value = e
		medicineListinit(leftmenu.value)
	}
</script>

<style lang="scss">
	.msgicon {
		width: 308rpx;
		margin: 100rpx auto;
		overflow: hidden;

		.msgtext {
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			font-size: 28rpx;
			color: #86909C;
			text-align: center;
			width: 100%;
			margin-top: 30rpx;
		}

		image {
			width: 308rpx;
		}
	}

	.tjyp1 {
		width: 100%;
		overflow: hidden;
		position: relative;

		.tjyp1back {
			width: 100%;
			height: 450rpx;
			background: linear-gradient(180deg, #CAEEFF 71%, rgba(240, 250, 255, 0) 100%);
			position: absolute;
			z-index: -1;
		}

		.yaoping {
			width: 236rpx;
			height: 72rpx;
			background: #EEF9FF;
			border-radius: 38rpx 0rpx 0rpx 38rpx;
			position: absolute;
			right: 0%;
			bottom: 5%;
			display: flex;
			align-items: center;
			font-weight: 400;
			font-size: 26rpx;
			color: #2AB4F5;

			.ypicon {
				width: 40rpx;
				height: 40rpx;
				margin-left: 24rpx;
				margin-right: 12rpx;
			}
		}

		.yybox {
			width: 100%;
			border-radius: 48rpx 48rpx 0rpx 0rpx;
			box-shadow: 0rpx -4rpx 8rpx 0rpx rgba(171, 227, 254, 0.31);
			background: #FFFFFF;
			height: 1330rpx;
			overflow: hidden;
			margin-top: 32rpx;
			display: flex;

			.rightcontent {
				width: 474rpx;
				height: 1300rpx;
				overflow-y: scroll;



				.centertexts {
					width: 100%;
					overflow: hidden;

					.itemyaoliang {
						min-height: 96rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						font-size: 30rpx;
						color: #1D2129;
						display: flex;
						align-items: center;
						justify-content: center;
						text-align: center;
					}
				}
			}

			.leftmenu {
				width: 276rpx;
				height: 1300rpx;
				overflow-y: scroll;
				background: #F7F8FA;
				border-right: 2rpx solid #E5E6EB;

				.itembox {
					width: 100%;
					min-height: 96rpx;
					text-align: center;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					display: flex;
					align-items: center;
					justify-content: center;
					font-size: 28rpx;
					color: #4E5969;
				}

				.bj {
					color: #FFFFFF;
					background: #2AB4F5;
				}
			}
		}

		.centersousuo {
			width: 686rpx;
			height: 76rpx;
			border-radius: 38rpx 38rpx 38rpx 38rpx;
			background: #FFFFFF;
			display: flex;
			align-items: center;
			margin: auto;
			margin-top: 24rpx;
			position: relative;

			.removeicon {
				width: 40rpx;
				height: 40rpx;
				position: absolute;
				right: 5%;
			}

			.ssicon {
				width: 32rpx;
				height: 32rpx;
				margin-left: 24rpx;
			}

			input {
				margin-left: 12rpx;
				font-size: 28rpx;
			}
		}
	}
</style>